var dataSize = 0;
$(function(){
	//获取在线资料
	loadQueryByRes_id();
	
	//加载所有文档简历
	loadDoc_resumesMessage();
	
	$("#myNav").affix({
        offset: { 
            top: 125 
      }
    });
});

function loadDoc_resumesMessage(){
	utilAjax("/doc_resumes/queryAllByBasic_id","","post",function(data){
		dataSize = data.list.length;
		var docCon = "<caption><font size='5' align='left'>所有文档简历</font></caption>";
		if(dataSize>=5){
			$("#uploadDoc").hide();
		}else{
			$("#uploadDoc").show();
		}
		if(dataSize!=0){
			docCon +="<tr class='info text-info'>" +
						"<th height='40'>文档标题</th>" +
						"<th>文档地址</th>"+
						"<th>操作</th>"+
					"</tr>";
			$.each(data.list,function(i,d){
				docCon +="<tr>" +
						"<th height='40'>"+d.doc_title+"</th>" +
						"<th>"+d.doc_url+"</th>"+
						"<th>" +
							"<input type='button' onclick=remove("+d.doc_id+") class='btn btn-primary' value='删除'>" +
						"</th>"+
					"</tr>";
			});
		}else{
			docCon += "<tr><td align='center'><font size='3' color='red'>暂无文档简历</font></td></tr>";
		}
		$("#allDoc_resumesTable").html(docCon);
	});
}
function remove(doc_id){
	utilAjax("/doc_resumes/removeDoc_resumes","doc_id="+doc_id,"post",function(data){
		if(data){
			alert("删除成功");
			loadDoc_resumesMessage();
		}else{
			alert("删除失败");
		}
	});
}

function loadQueryByRes_id(){
	utilAjax("/online_resumes/queryByRes_id","","post",function(data){
		if(data!=null){
			$("#fileImg2").attr("src","/image/"+data.resumes.res_photo);
			$("#res_id").val(data.resumes.res_id);
			$("#res_name").val(data.resumes.res_name);
			var gender = data.resumes.res_gender;
			if(gender==1){
				$("input[type='radio'][name='res_gender'][value='1']").attr("checked",true);
			}else if(gender==2){
				$("input[type='radio'][name='res_gender'][value='2']").attr("checked",true);
			}
			
			$("#res_date").val(data.resumes.res_date);
			$("#res_pa").val(data.resumes.res_pa);
			
			$("#res_jeMin[value='"+data.resumes.res_jeMin+"']").val("selected",true);
			$("#res_jeMax[value='"+data.resumes.res_jeMax+"']").val("selected",true);
			
			$("#res_we").val(data.resumes.res_we);
			
			$("#res_pe").val(data.resumes.res_pe);
			var res_ee = data.resumes.res_ee;
			var res_workYear = data.resumes.res_workYear;
			$("#res_ee [value='"+res_ee+"']").attr("selected",true);
			$("#res_workYear [value='"+res_workYear+"']").attr("selected",true);
		}
		
	});
}


var imgurl2 = "";
function getImgUR2L(node) {	
	var imgURL = "";	
    try{
        var file = null;
        if(node.files && node.files[0] ){
        	file = node.files[0]; 
        }else if(node.files && node.files.item(0)) {                    			
        	file = node.files.item(0);   
        } 	
        try{
			imgURL =  file.getAsDataURL();  
        }catch(e){
        	imgRUL = window.URL.createObjectURL(file);
        }
     }catch(e){     		
        if (node.files && node.files[0]) {                    		
        	var reader = new FileReader(); 
        	reader.onload = function (e) {                      	        	
        	    imgURL = e.target.result;  
        	};
        	reader.readAsDataURL(node.files[0]); 
        }  
     }
	creatImg(imgRUL);
	return imgURL;
}
function creatImg(imgRUL){   //根据指定URL创建一个Img对象
	$("#fileImg2").attr("src",imgRUL);
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}

function checkMyFile(){
	//允许上传的文档
	var typeAllow = ["doc","docx"];
	 
	//判断上传的文档是否是docx类型
	var myFile = $('#myFile').get(0).files[0];
	if(myFile==undefined){
		$('#myFile').css("border","1px solid red");
		alert("请选择文档！！！");
		return false;
	}else{
		var addFile = $('#myFile').val();
		var fileType = (addFile.substring(addFile.lastIndexOf(".")+1,addFile.length)).toLowerCase();
		if($.inArray(fileType,typeAllow)<0){
			$('#myFile').css("border","1px solid red");
			alert("请传入正确的文件格式，以下为正确后缀：.doc / .docx "); 
		}else{
			 $("#myFile").css("border", "");
			return true;
		}
	}
	return false;	
}

function checkImgMyFile(){
	//判断文本域是否有值  并判断是否是图片
	var myFile = $('#myFile2').get(0).files[0];
	var reader = new FileReader();// 操作图片
	
	if(myFile==undefined){
		$('#myFile2').css("border","1px solid red");
		alert("请选择头像！！！");
		return false;
	}else{
		var imageType = $('#myFile2').get(0).files[0].type;
		if(imageType.substring(0,imageType.indexOf("/"))!="image"){
			$('#myFile2').css("border","1px solid red");
			alert("请选择图片类型的文件！！！");
			return false;
		}else{
			 $("#myFile2").css("border", "");
			return true;
		}
	}
	return false;	
}